package com.etoak.common.web.utils;

import ch.qos.logback.core.util.StringUtil;
import com.github.pagehelper.PageHelper;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;

public class PageUtil {
    public static final String PAGE_NUM="pageNum";

    public static final String PAGE_SIZE="pageSize";

    /**
     * 设置页码参数
     */
    /**
     * 初始化分页信息
     * 从请求参数中获取页码和每页大小，并设置分页助手
     */
    public static void startPage(){
        /**
         * 先获取HttpServletRequest对象
         */
        HttpServletRequest request = ServletUtil.getRequest();

        int pageNum = StringUtils.isNotBlank(request.getParameter(PAGE_NUM)) ?
                Integer.parseInt(request.getParameter(PAGE_NUM)) : 1;

        int pageSize = StringUtils.isNotBlank(request.getParameter(PAGE_SIZE)) ?
                Integer.parseInt(request.getParameter(PAGE_SIZE)) : 10;

        PageHelper.startPage(pageNum,pageSize);
    }
}
